package health.lm.com.order.presenter;

import health.lm.com.component_base.base.mvp.contract.XPresent;
import health.lm.com.component_base.pay.PaymentEntity;
import health.lm.com.network.callback.SimpleCallBack;
import health.lm.com.order.activity.ActivationActivity;
import health.lm.com.order.activity.ActivityPayActivity;
import health.lm.com.order.entity.ActivityPayEntity;
import health.lm.com.order.entity.PayResultEntity;
import health.lm.com.order.model.OrderModel;

/**
 * @description 活动支付
 * @author GQI
 * @date :2019-08-16 17:03
 */
public class ActivityPayPresenter extends XPresent<ActivityPayActivity> {
    public void getData(String id) {
        OrderModel.getInstance().activityInfo(id, new SimpleCallBack<ActivityPayEntity>() {
            @Override
            public void onSuccess(ActivityPayEntity entity) {
                if (hasV()) {
                    getV().getDataSuccess(entity);
                }
            }
        });

    }

    public void getReadyPay(String id, int pay_type,String coin) {
        OrderModel.getInstance().activity(id, pay_type,coin, new SimpleCallBack<PaymentEntity>() {
            @Override
            public void onSuccess(PaymentEntity paymentEntity) {
                if (hasV()) {
                    getV().paymentData(paymentEntity);
                }
            }
        });
    }

    public void resultCheck(String order_sn, int pay_type) {
        OrderModel.getInstance().checkPayState(order_sn, pay_type, new SimpleCallBack<PayResultEntity>() {
            @Override
            public void onSuccess(PayResultEntity entity) {
                if (hasV()){
                    //status 0 支付失败 1支付成功
                    if (entity.getStatus() == 1){
                        getV().aliPaySuccess();
                    }else {
                        getV().aliPayFail();
                    }
                }
            }
        });
    }
}
